Uec3.CompanyClientWindow = Ext.extend(Ext.app.Module,{
	id: 'companyClient',
   /*
    * Initialize this module.
    * This function is called at startup (page load/refresh).
    */
   init : function(initParams){
   
   },
 
   getComponent:function(){
   			
   			var _this = this;
   			// 区县下拉框
			var district_cmb = getDistrictCombox(Uec3.App.Constants.homeUrl);
			district_cmb.setWidth(100);
			district_cmb.anchor="100%";
			// 城市下拉框
			var city_cmb = getCityCombox(Uec3.App.Constants.homeUrl,district_cmb);
			city_cmb.setWidth(100);
			city_cmb.anchor="100%";
			// 省份下拉框
			var province_cmb = getProvinceCombox(Uec3.App.Constants.homeUrl,city_cmb, district_cmb);
			province_cmb.setWidth(100);
			province_cmb.anchor='100%';
		    
			var isPaid_store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'package_is_overdue'});
			var isPaid_combox = getDictionaryComboBox(isPaid_store,'local','paid','套餐是否过期','paid','','100%');		
			
			var realType_store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'requestReal_type'});
			var realType_combo= getDictionaryComboBox(realType_store,'local','realType','认证类型','realType','','100%');
			
			var companyType_store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'company_rtype'});
			var companyType_combo = getDictionaryComboBox(companyType_store,'local','companyType','认证类型','companyType','','100%');
			
			var companyStatus_store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'company_status'});
			var companyStatus_combo = getDictionaryComboBox(companyStatus_store,'local','status','状态','status','','100%');
			
			province_cmb.on('select', function(combo) {
					var value = combo.getValue();
					search_form.getForm().findField("areaId").setValue(value);
			});

			city_cmb.on('select', function(combo) {
					var value = combo.getValue();
					search_form.getForm().findField("areaId").setValue(value);
			});

			district_cmb.on('select', function(combo) {
					var value = combo.getValue();
					search_form.getForm().findField("areaId").setValue(value);
			});

			
		    var search_form = new Ext.FormPanel({
   	       		frame:true,
   	      		border:false,
   	       	    items:[{
   	          		layout:'column',
   	          		items:[{
   	             		columnWidth:0.13,
   	             		items:[{ 
   	                		layout:'form',
   	                		labelWidth:28,
   	                		items:[province_cmb]}]
   	           		  },{
   	           	 		columnWidth:0.13,
   	            		items:[{ 
   	                		layout:'form',
   	                		labelWidth:28,
   	                		items:[city_cmb]}]
   	           		 },{
   	           	 		columnWidth:0.13,
   	             		items:[{ 
   	                		layout:'form',
   	                		labelWidth:28,
   	                		items:[district_cmb]}]
   	          		 },{
   	              		columnWidth:0.17,
   	             		items:[{ 
   	                		layout:'form',
   	                		labelWidth:76,
   	                		items:[isPaid_combox]}]    	           
   	           		 },{
   	           	 		columnWidth:0.22,
   	             		items:[{ 
   	                		layout:'form',
   	                		labelWidth:52,
   	                		items:[realType_combo]}]    	
   	           		 },{
   	           	 		columnWidth:0.22,
   	             		items:[{ 
   	                		layout:'form',
   	                		labelWidth:52,
   	                		items:[companyType_combo,{xtype:'hidden',name:'areaId'}]}]    	
   	                 },{
   	                    xtype:'button',
				        text:'查找',
				        //style:{marginLeft:'15px',width:'75px'},
				        handler:searchCompanyByCondition
   	                 }
   	            ]}
   	         ]
   	      });
   	      
   	      var companyGrid_store = new Ext.data.JsonStore({
   	  			url:Uec3.App.Constants.homeUrl+"/company/companyManage.do",
   	  			root:'root',
   	  			totalProperty:'totalProperty',
   	  		    fields:['id','name','contactor','taxCode','code','business','province','city','tel','status','realType','companyType',{name:'gmtCreate',type:'date',dateFormat:'Y-m-d H:i:s'}],
   	  		    listeners :{
                  'beforeload':function(){
                       Ext.MessageBox.wait("正在加载数据...","提示");
                   }            
                }
   	      });
   	     
   	     	//创建工具栏组件
		  var toolbar = new Ext.Toolbar({
		     items:[
			    {text : '赠送U币',iconCls : 'icon-add',itemId:'present',handler:presentPackage},
			    {text : '开通/停止零件上传服务',iconCls : 'icon-edit',itemId:'halt',handler:openOStopService}			 
		     ]
		  });
   	      
          var column = new Ext.grid.ColumnModel({
          		columns:[
          		   	new Ext.grid.RowNumberer(),
      		 	   	{header:'公司名称',dataIndex:'name'},
      		 		{header:'负责人/法人',dataIndex:'contactor'},
      		 		{header:'工商注册号',dataIndex:'code'}, 
      		 		{header:'税号',dataIndex:'taxCode'},
      		 		{header:'经营项目',dataIndex:'business'},
      		 		{header:'省份',dataIndex:'province'},
      		 		{header:'城市',dataIndex:'city'},
      		 		{header:'联系电话',dataIndex:'tel'},
      		 		{header:'状态',dataIndex:'status',renderer:Ext.util.Format.comboRenderer(companyStatus_combo)},
      		 		{header:'注册时间',dataIndex:'gmtCreate',renderer:Ext.util.Format.dateRenderer('Y-m-d')}, 
      		 		{header:'认证类型',dataIndex:'realType',renderer:Ext.util.Format.comboRenderer(realType_combo)},
      		 		{header:'公司类型',dataIndex:'companyType',renderer:Ext.util.Format.comboRenderer(companyType_combo)}
          		],
          		defaults: {
          			menuDisabled: true         
       			}
          });
      		 
        
         var company_grid = new Ext.grid.GridPanel({
      		 viewConfig:{forceFit:true,scrollOffset:20},	   	   
	   	   	 autoScroll : true,
	   	   	 titleCollapse:true,
	         colModel:column,
	         height:250,
	         selModel:new Ext.grid.RowSelectionModel({moveEditorOnEnter:true,singleSelect :true}),
	         store:companyGrid_store,	           
	         columnLines :true,
	         tbar:toolbar,
	         bbar: new Ext.PagingToolbar({
		            pageSize:19,
	                store:companyGrid_store,
	                displayInfo: true,
	                displayMsg: '第 {0} - {1} 条  共 {2} 条',
                    emptyMsg: "没有记录",                   
                    listeners:{
                        beforechange:function(){
                      		 Ext.MessageBox.wait("正在加载数据...","提示");	                     
                        },
                        change:function(){
                            Ext.MessageBox.hide();
                        }
                    }
		     })
         });
   	      
         
   	     function searchCompanyByCondition(){
   	     	var queryParam = Ext.encode(search_form.getForm().getValues());
   	     	loadCompany(queryParam);
   	     }
   	     
   	     function presentPackage(){
   	     	var record = company_grid.getSelectionModel().getSelected();
   	     	if(Ext.isEmpty(record)){
   	     		Ext.MessageBox.alert("提示","请选择公司!");
   	     	}else{
   	     		_this.app.desktop.launchWindowByParam("presentPackage",{companyId:record.data.id,companyName:record.data.name});
   	     	}
   	     }
   	     
   	     function openOStopService(){
   	     	var record = company_grid.getSelectionModel().getSelected();
   	     	if(Ext.isEmpty(record)){
   	     		Ext.MessageBox.alert("提示","请选择公司!");
   	     	}else{
   	     		_this.app.desktop.launchWindowByParam("presentService",{companyId:record.data.id,companyName:record.data.name});
   	     	}
   	     }
   	     
   	     function loadCompany(queryParam){
   	     	 if(queryParam){
				 companyGrid_store.baseParams={start:0,limit:19,queryParam:queryParam}; 
			 }else{
			 	 companyGrid_store.baseParams={start:0,limit:19}; 				 
			 }
			 companyGrid_store.load({callback:function(records,options,success){
	              if(success){
	                 var total=records.length;
	                 if(Ext.isEmpty(total)){
	                    Ext.MessageBox.alert("提示","未找到相关记录");
	                 }
	              }else{
	                 Ext.MessageBox.alert("提示","数据加载异常");
	              }
		    }});
   	     }
   	    function init(){
   	       realType_store.load();
   	       companyType_store.load();
   	       companyStatus_store.load();
   	       isPaid_store.load();
   	       loadCompany();
   	    } 
   	    
   	    init();
   	    
   	     
   	     var join_panel = new Ext.Panel({
             border:false,
             items:[search_form,company_grid]
         });
         
         return join_panel;
   },
   
   /**
	* Create this modules window here.
	*/
   createWindow : function(params){
    	var desktop = this.app.getDesktop();
        var win = desktop.getWindow('companyClient');
        if (!win) {
			win = desktop.createWindow({
				        id : "companyClient",
						title : '公司用户管理',
						width : 1000,
						height : 500,
						iconCls : 'acc-icon',
					    minWidth:1000,
						maximizable : true,
						maximized:true,
						//autoScroll : true,
						constrainHeader : true,
						taskbuttonTooltip : "公司用户管理",
						//layout : "fit",
						items : [this.getComponent(params)]
					});
		}
		win.get(0).get(1).setHeight(win.getHeight()-70);
    	win.show(); 
        win.on('resize',function(win,width,height){
      	   win.get(0).get(1).setHeight(height-72);
        });
   }
});